﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HTML;
using System.Net;


namespace HTML
{

    public class HtmlDoc 
    {
        private WebClient client;
        private String title;
        private String url;
        private IList<string> links;
        public IList<string> AllLinks;
        private IHtmlDocRegEx parser;
        private Uri uri;

        public HtmlDoc(string url)
        {
            client = new WebClient();
            try
            {
                this.uri = new Uri(url);
            }
            catch (Exception)
            {
                
            }
            
            
            
        }
        //
        public String Title
        {
            get { return title;}
            set { value = title;}
        }
        //
        public String Url
        {
            get { return url;}
            set { value = url;}
        }
        //
        public Uri Uri
        {
            get { return uri; }
            set { value = uri; }
        }
        //
        /*public IList<string> AllLinks
        { 
            get { return links; } 
        }
         */
        //
        public IList<string> GetAllLinks()
        {
            
            try
            {
                if (links == null)
                {
                    parser = new HtmlDocRegEx(uri.Host, uri.OriginalString, client.DownloadString(uri.OriginalString));
                    links = parser.GetHrefs();
                    links = links.Distinct().ToList();
                }
            }
            catch (Exception ex)
            {
                
            }
            return links;
        }
    }
}
